home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / c_scripts / klogd.txt < prev    next >
Encoding:
Text File  |  1998-12-05  |  2.9 KB  |  80 lines

  1. [ http://www.rootshell.com/ ]
  2.  
  3. Date:         Thu, 10 Sep 1998 10:26:06 +0200
  4. From:         Michal Zalewski <lcamtuf@IDS.PL>
  5. Subject:      [Linux] klogd 1.3-22 buffer overflow
  6.  
  7. Good morning,
  8.  
  9. This time - buffer overflow in Linux klogd daemon from sysklogd-1.3
  10. package (up to release 22 - affects Red Hat 5.x and Slackware 3.x, no data
  11. about other distributions).
  12.  
  13. The problem:
  14.  
  15. Kernel messages are stored in 4 kB cyclic printk ring. Klogd reads this
  16. buffer using /proc/kmsg to 4 kB long buffer, that's good. But then, data
  17. is split into lines, by copying data until '\n' is reached. What a pity,
  18. line buffer is only 1 kB long - sometimes, it's not enough... Exploitable?
  19. Could be...
  20.  
  21. Impact:
  22.  
  23. To exploit this security hole, we have to generate very long kernel
  24. message (or a lot of short messages with no '\n' inside). There are two
  25. potential ways of doing this:
  26.  
  27. a) In kernel source (or any of installed modules), find printk not
  28.    terminated with '\n'. There are some old, obscure messages both in
  29.    2.0.xx and 2.1.xxx. Yep, but what now? You have to generate it :-S
  30.    It's especially easy when poking with strange network packets
  31.    (so it's possible to perform remote DoS attack). Unfortunately, DoS
  32.    if probably all you can do - enjoy SEGV in klogd daemon, or (better?),
  33.    by overwriting fd to /proc/kmsg lyingo on the stack, increase LA and
  34.    generate enormous amount of error messages like 'Cannot read /proc
  35.    filesystem', apparently from kernel.
  36.  
  37. b) ...or, in kernel (2.1.xxx is more interesting), locate any printk with
  38.    %s in format string, where substituted string depends in some way on
  39.    luser (process/filename?). Then, you should be able to parse arbitrary
  40.    shellcode into buffer, obtaining root privledges.
  41.  
  42. Solution:
  43.  
  44. In klog.c, at the beginning, there are two '#define's. First one is
  45. responsible for main buffer size - don't change it, 4096 should be ok. The
  46. next one is line buffer size - hmm, replace 1024 with 4096, for example...
  47. Or, better, implement some range checking ;>
  48.  
  49. Quick vunerability test:
  50.  
  51. -- gcc -c -O3 test.c; insmod test; rmmod test --
  52. #define MODULE
  53. #define __KERNEL__
  54.  
  55. #include <linux/module.h>
  56. #include <linux/kernel.h>
  57. #include <linux/types.h>
  58. #include <linux/string.h>
  59. #include <linux/malloc.h>
  60. #include <asm/unistd.h>
  61. #include <linux/version.h>
  62. #include <asm/string.h>
  63.  
  64. int init_module(void) {
  65.   printk("INSERT_ABOUT_2000_BYTES_OF_JUNK_HERE\n"); return 0;
  66. }
  67.  
  68. void cleanup_module(void) {}
  69. --
  70.  
  71. Modify this source by increasing amount of junk after printk, compile,
  72. insmod and watch out what happened to klogd.
  73.  
  74. _______________________________________________________________________
  75. Michal Zalewski [lcamtuf@ids.pl] [ENSI / marchew] [dione.ids.pl SYSADM]
  76. [http://linux.lepszy.od.kobiety.pl/~lcamtuf/] <=--=> bash$ :(){ :|:&};:
  77. [voice phone: +48 (0) 22 813 25 86] ? [pager (MetroBip): 0 642 222 813]
  78. Iterowac jest rzecza ludzka, wykonywac rekursywnie - boska [P. Deutsch]
  79.  
  80.